package com.glsc.ngateway.flowable.service;

import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableDemandDto;
import com.glsc.ngateway.common.base.converter.flowable.FlowableDemandConverter;
import com.glsc.ngateway.common.base.domain.mysql.flowable.FlowableDemand;
import com.glsc.ngateway.common.base.repo.mysql.flowable.FlowableDemandRepo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.constraints.NotNull;
import java.util.List;

@Service
public class FlowableDemandService {

    private static final Logger logger = LoggerFactory.getLogger(FlowableDemandService.class);

    @Autowired
    FlowableDemandRepo flowableDemandRepo;

    @Transactional
    public void saveDemandSubmit(@NotNull FlowableDemandDto flowableDemand) {
        flowableDemandRepo.save(FlowableDemandConverter.dto2Domain(flowableDemand));
    }

    public List<FlowableDemandDto> findByProcessInstanceId(String processInstanceId) {
        return FlowableDemandConverter.domain2Dto(flowableDemandRepo.findByProcessInstanceId(processInstanceId));
    }

    public List<FlowableDemandDto> findByRequestId(String requestId) {
        return FlowableDemandConverter.domain2Dto(flowableDemandRepo.findByRequestId(requestId));
    }

    public List<FlowableDemand> findByProcessInstanceIdIn(List<String> processIds) {
        return flowableDemandRepo.findByProcessInstanceIdIn(processIds);
    }

    public List<FlowableDemand> findByVcStaffLikeOrVcOriginalStaffOrDevUserId(String vcStaff, String vcOriginalStaff, String devUserId, List<String> sameDepartmentAccounts, String demandDetail) {
        return flowableDemandRepo.findByVcStaffLikeOrVcOriginalStaffOrDevUserId(vcStaff,vcOriginalStaff,devUserId,sameDepartmentAccounts,demandDetail);
    }
}